package 实现多线程;
/*
* 实现多线程方式2：实现Runnable接口(应用)
* Thread构造方法
* Thread(Runnable target) 分配一个新的Thread对象
* Thread(Runnable target,String name) 分配一个新的Thread对象
* */
public class 实现多线程方式2 {
    public static void main(String[] args) {
        /*创建MyRunnable类的对象*/
        MyRunnable my = new MyRunnable();
        /*创建Thread类的对象，把MyRunnable对象作为构造方法的参数*/
        Thread t1 = new Thread(my, "高铁");
        Thread t2 = new Thread(my, "飞机");
        /*启动线程*/
        t1.start();
        t2.start();
    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+":"+i);
        }
    }
}